package vsqlbuilder;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import vsqlbuilder.gui.MainView;
import vsqlbuilder.gui.SplashScreen;

public class Vsqlbuilder {

    private static final int SPLASH_DELAY = 6000;	
    
    
    
    private Vsqlbuilder(){
    }

      
	/**
	 * This function is the main function of the Visual SQL Builder Tool
	 * and it's in charge of begin the application loading.
	 * 
	 * @param args Console arguments for the Visual SQL Builder Tool
	 */
	public static void main(String[] args) {
		try{
			StartGUI();
		}catch (RuntimeException e){
			exitApplication();
		}
	}
	
		public static void exitApplication() {
			//TODO [high]: this part of the application must end all unfinished functions/process
			   System.out.println("Shutting down application");
			   System.exit(0);
	        }

		
		 private static void StartGUI() {

			    final MainView frame = new MainView();
			 
				SwingUtilities.invokeLater(new Runnable() {

				    public void run() {

					SplashScreen.splash(frame);
				    }
				});

								
//				    UIManager.setLookAndFeel(new PlasticXPLookAndFeel());
					try {
						UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
					} catch (ClassNotFoundException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					} catch (InstantiationException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					} catch (IllegalAccessException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					} catch (UnsupportedLookAndFeelException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}

			 
				 Timer t;
			    	//Set hide window timer
			    	Action hideWindow = new AbstractAction() {
			    		static final long serialVersionUID = 0L;
			    	    public void actionPerformed(ActionEvent e) {
			    	    	SplashScreen.disposeSplash();
							frame.setVisible(true);
			    	    }
			    	};

			    	t = new Timer(SPLASH_DELAY, hideWindow);
	    	    	t.setRepeats(false);
		    		t.start();
		 }
		
		 
}
